<?php
/**
 * @version 0.8.3 2010-10-07
 * @package Joomla
 * @subpackage LeagueResults
 * @copyright (C)  2008, 2009, 2010 Henryk Drozd
 * @license GNU/GPL, see LICENSE.php
 * LeagueResults is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License 2
 * as published by the Free Software Foundation.

 * LeagueResults is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.




 */
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.model');


class lrModelClub extends JModel
{
var $_id = null;
var $_data = null;

function __construct()
	{
		parent::__construct();

		$array = JRequest::getVar('cid',  0, '', 'array');
		$this->setId((int)$array[0]);
	}
function setId($id)
	{
		$this->_id	    = $id;
		$this->_data	= null;
	}

function &getData()
	{
		if ($this->_loadData())
		{

		}
		else  $this->_initData();

		return $this->_data;
	}
function _loadData()
	{
		// Lets load the content if it doesn't already exist
		if (empty($this->_data))
		{
			$query = 'SELECT *'
					. ' FROM #__lr_clubs'
					. ' WHERE id = '.$this->_id
					;

			$this->_db->setQuery($query);

			$this->_data = $this->_db->loadObject();

			return (boolean) $this->_data;
		}
	return true;
	}
	
	function _initData()
	{
		// Lets load the content if it doesn't already exist
		if (empty($this->_data))
		{
			$club = new stdClass();
			$club->id				= 0;
			$club->name				= null;
			$club->shortname		= null;
			$club->address1			= null;
			$club->address2			= null;
			$club->city				= null;
			$club->postcode			= null;
			$club->contact_person	= null;
			$club->phone			= null;
			$club->email			= null;
			$club->url				= null;
			$club->published		= 1;
			
			$this->_data			= $club;
			return (boolean) $this->_data;
		}
		return true;
	}
	
	
	function store($data)
	{
		$lrsettings = lrAdmin::config();
		$user		= & JFactory::getUser();
		$config 	= & JFactory::getConfig();

		$tzoffset 	= $config->getValue('config.offset');

		$row  =& $this->getTable('lr_clubs', '');

		if (!$row->bind($data)) {
			JError::raiseError(500, $this->_db->getErrorMsg() );
			return false;
		}

		jimport('joomla.filesystem.file');
		
		$row->id = (int) $row->id;

		$nullDate	= $this->_db->getNullDate();

		// Make sure the data is valid
		if (!$row->check($lrsettings)) {
			$this->setError($row->getError());
			return false;
		}

		// Store it in the db
		if (!$row->store()) {
			JError::raiseError(500, $this->_db->getErrorMsg() );
			return false;
		}

		return $row->id;
	}
	
}

?>